//
//  AttentionDetailController.m
//  PropertyMananger
//
//  Created by bh on 16/12/30.
//  Copyright © 2016年 BH. All rights reserved.
//

#import "AttentionDetailController.h"
#import "AttentionDetailCell.h"
#import "NickNameCell.h"

@interface AttentionDetailController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) NSArray * titleArray;
@end

@implementation AttentionDetailController

static NSString * headerID = @"headerID";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTitleViewName:@"通讯录详情"];
   self.view.backgroundColor = [UIColor whiteColor];
   
    [self initTableViewWithView:self.view frame:CGRectMake(0, 0, BHscreenW, BHscreenH- 64) isGroup:NO];
    self.titleArray = @[@"手机号:",@"分机号:"];
    
}
- (NSArray *)detailArr
{
    if (!_detailArr) {
        
        _detailArr = [[NSMutableArray alloc]init];
        
    }
    return _detailArr;
}
#pragma mark -代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section == 1){
    
        if (self.model.OfficePhone == nil) {
            
            return 1;
        }else{
         return self.titleArray.count;
        }
       
    }
    return 1;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        
        NickNameCell * nickCell = [NickNameCell cellWithTableView:tableView];
        nickCell.nickNameLabel.text = self.model.RealName;
        nickCell.subNameLabel.text = self.model.Duty;
        
        DLog(@"RealName == %@",self.model.RealName);
        if (self.attentionTag == 300)
        {
        nickCell.headerImg.image = IMG(@"ico_mail_list_property");
        }else if (self.attentionTag == 310)
        {
        nickCell.headerImg.image = IMG(@"ico_owner_inquiry");
        }
        return nickCell;
    }else if (indexPath.section == 1)
    {
        AttentionDetailCell * cell = [AttentionDetailCell cellWithTableView:tableView];
        cell.titleLabel.text = self.titleArray[indexPath.row];

        if (indexPath.row == 0)
        {
            
            [cell.phoneButton addTarget:self action:@selector(phoneButtonClick:) forControlEvents:UIControlEventTouchUpInside];
               cell.phoneNum.text = self.model.Tel;
            DLog(@"电话 == %@",self.model.Tel);
            
        }else if (indexPath.row == 1)
        {
            
        [cell.phoneButton addTarget:self action:@selector(phoneButtonClick1:) forControlEvents:UIControlEventTouchUpInside];
           cell.phoneNum.text = self.model.OfficePhone;
        }
        
        
        return cell;
    }
    
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 75;
    }else if (indexPath.section == 1)
    {
    return 50;
    }
    return 0;
}
#pragma makr - 点击打电话
- (void)phoneButtonClick:(UIButton *)button
{
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",self.model.Tel];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];

}
- (void)phoneButtonClick1:(UIButton *)button
{
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",self.model.OfficePhone];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];

}
@end
